package edu.gatech.doi.spamframework.gui;

import java.awt.event.KeyEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;
import java.awt.Event;
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.Graphics;

import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.KeyStroke;
import java.awt.Point;

import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JFrame;
import javax.swing.JDialog;
import javax.swing.JPopupMenu;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.swing.JInternalFrame;
import javax.swing.JSplitPane;
import javax.swing.JDesktopPane;
import javax.swing.JTree;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JEditorPane;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.PlainDocument;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeCellEditor;
import javax.swing.tree.TreePath;

import moa.gui.GUI;
import moa.gui.GUIDefaults;
import moa.gui.GUIUtils;
import moa.gui.TaskLauncher;
import moa.gui.TaskManagerPanel;
import moa.gui.clustertab.ClusteringVisualTab;

import org.bounce.text.ScrollableEditorPanel;
import org.bounce.text.xml.XMLEditorKit;
import org.bounce.text.xml.XMLStyleConstants;

import weka.gui.MOAClassOptionEditor;
import weka.gui.experiment.Experimenter;

import edu.gatech.doi.spamframework.core.DataSourceTypes;
import edu.gatech.doi.spamframework.core.MappingXMLFiles;
import edu.gatech.doi.spamframework.core.ModelTypes;
import edu.gatech.doi.spamframework.core.ModelXMLFiles;
import edu.gatech.doi.spamframework.filters.GenerateROC;
import edu.gatech.doi.spamframework.mapping.MappingAttribute;
import edu.gatech.doi.spamframework.mapping.PropertiesFileOperator;
import edu.gatech.doi.spamframework.model.ModelAttribute;
import edu.gatech.doi.spamframework.model.XMLOperator;
import javax.swing.BoxLayout;
import javax.swing.JTabbedPane;
import java.awt.GridLayout;
import java.awt.Rectangle;
import javax.swing.JButton;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JTextField;



public class SpamDetectionFramework {

	private JFrame jFrame = null;  //  @jve:decl-index=0:visual-constraint="46,0"
	private JMenuBar jJMenuBar = null;
	private JMenu fileMenu = null;
	private JMenu helpMenu = null;
	private JMenuItem exitMenuItem = null;
	private JMenuItem aboutMenuItem = null;
	private JMenuItem saveMenuItem = null;
	private JDialog aboutDialog = null;
	private JPanel aboutContentPane = null;
	private JLabel aboutVersionLabel = null;
	private JMenu Configuration = null;
	private JSplitPane jSplitPane = null;
	private JTree jTree = null;
	private JSplitPane jSplitPane1 = null;
	private JScrollPane jScrollPane = null;
	private JTable jTable = null;
	private JEditorPane jEditorPane = null;
	private JMenu jMenu = null;
	private JMenuItem jMenuItem = null;
	private XMLEditorKit kit=null;
	private JScrollPane jScrollPane1 = null;
	private JMenuItem jMenuItem1 = null;
	private JMenuItem jMenuItem2 = null; 
	private FileChooserDemo fcd=new FileChooserDemo();
	private String jEditorFilePath=null;
	private Document doc=null;
	private JScrollPane jScrollPane3 = null;
	private JScrollPane jScrollPane4 = null;
	private JTable jTable1 = null;
	private JDialog jPropertiesDialog = null;  //  @jve:decl-index=0:visual-constraint="560,645"
	private JPanel jPropertiesContentPane = null;
	private JScrollPane jScrollPane2 = null;
	private JTable jTable11 = null;
	private JDialog jAlterDialog = null;  //  @jve:decl-index=0:visual-constraint="291,717"
	private JPanel jAlterContentPane = null;
	private JLabel jAlterLabel = null;
	private  String propertiesfilepath=null;
	private JDialog jAddDialog = null;  //  @jve:decl-index=0:visual-constraint="-8,852"
	private JPanel jAddContentPane = null;
	private JTextField jAddKeyTextField = null;
	private JLabel jAddKeyLabel = null;
	private JTextField jAddValueTextField = null;
	private JLabel jAddValueLabel = null;
	private JButton jAddConfirmButton = null;
	private JButton jAddResetButton = null;
	private int datasourcelimit=100;
	private int modellimit=100;
	private JMenuItem jExMenuItem3 = null;
	/**
	 * This method initializes jFrame
	 * 
	 * @return javax.swing.JFrame
	 */
	private JFrame getJFrame() {
		if (jFrame == null) {
			jFrame = new JFrame();
			jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			jFrame.setResizable(false);
			jFrame.setJMenuBar(getJJMenuBar());
			jFrame.setSize(800, 600);
			jFrame.setTitle("SpamDetectionFramework");
//			jFrame.setContentPane(getJTabbedPane());
			jFrame.setContentPane(getJSplitPane());
			jFrame.setVisible(true);
		}
		return jFrame;
	}

	/**
	 * This method initializes jJMenuBar	
	 * 	
	 * @return javax.swing.JMenuBar	
	 */
	private JMenuBar getJJMenuBar() {
		if (jJMenuBar == null) {
			jJMenuBar = new JMenuBar();
			jJMenuBar.add(getFileMenu());
			jJMenuBar.add(getConfiguration());
			jJMenuBar.add(getJMenu());
			jJMenuBar.add(getHelpMenu());
		}
		return jJMenuBar;
	}

	/**
	 * This method initializes jMenu	
	 * 	
	 * @return javax.swing.JMenu	
	 */
	private JMenu getFileMenu() {
		if (fileMenu == null) {
			fileMenu = new JMenu();
			fileMenu.setText("File");
			fileMenu.add(getSaveMenuItem());
			fileMenu.add(getExitMenuItem());
		}
		return fileMenu;
	}

	/**
	 * This method initializes jMenu	
	 * 	
	 * @return javax.swing.JMenu	
	 */
	private JMenu getHelpMenu() {
		if (helpMenu == null) {
			helpMenu = new JMenu();
			helpMenu.setText("Help");
			helpMenu.add(getAboutMenuItem());
		}
		return helpMenu;
	}

	/**
	 * This method initializes jMenuItem	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getExitMenuItem() {
		if (exitMenuItem == null) {
			exitMenuItem = new JMenuItem();
			exitMenuItem.setText("Exit");
			exitMenuItem.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					System.exit(0);
				}
			});
		}
		return exitMenuItem;
	}

	/**
	 * This method initializes jMenuItem	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getAboutMenuItem() {
		if (aboutMenuItem == null) {
			aboutMenuItem = new JMenuItem();
			aboutMenuItem.setText("About");
			aboutMenuItem.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					JDialog aboutDialog = getAboutDialog();
					aboutDialog.pack();
					Point loc = getJFrame().getLocation();
					loc.translate(20, 20);
					aboutDialog.setLocation(loc);
					aboutDialog.setVisible(true);
				}
			});
		}
		return aboutMenuItem;
	}

	/**
	 * This method initializes aboutDialog	
	 * 	
	 * @return javax.swing.JDialog
	 */
	private JDialog getAboutDialog() {
		if (aboutDialog == null) {
			aboutDialog = new JDialog(getJFrame(), true);
			aboutDialog.setTitle("About");
			aboutDialog.setContentPane(getAboutContentPane());
		}
		return aboutDialog;
	}

	/**
	 * This method initializes aboutContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getAboutContentPane() {
		if (aboutContentPane == null) {
			aboutContentPane = new JPanel();
			aboutContentPane.setLayout(new BorderLayout());
			aboutContentPane.add(getAboutVersionLabel(), BorderLayout.CENTER);
		}
		return aboutContentPane;
	}

	/**
	 * This method initializes aboutVersionLabel	
	 * 	
	 * @return javax.swing.JLabel	
	 */
	private JLabel getAboutVersionLabel() {
		if (aboutVersionLabel == null) {
			aboutVersionLabel = new JLabel();
			aboutVersionLabel.setText("Version 1.0");
			aboutVersionLabel.setHorizontalAlignment(SwingConstants.CENTER);
		}
		return aboutVersionLabel;
	}

	/**
	 * This method initializes jMenuItem	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getSaveMenuItem() {
		if (saveMenuItem == null) {
			saveMenuItem = new JMenuItem();
			saveMenuItem.setText("Save");
			saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
					Event.CTRL_MASK, true));
		}
		return saveMenuItem;
	}

	/**
	 * This method initializes Configuration	
	 * 	
	 * @return javax.swing.JMenu	
	 */
	private JMenu getConfiguration() {
		if (Configuration == null) {
			Configuration = new JMenu();
			Configuration.setText("Experiments");
			Configuration.setToolTipText("Experiments on datasets");
			Configuration.add(getJExMenuItem3());
			Configuration.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
				}
			});
		}
		return Configuration;
	}

	/**
	 * This method initializes jSplitPane	
	 * 	
	 * @return javax.swing.JSplitPane	
	 */
	private JSplitPane getJSplitPane() {
		if (jSplitPane == null) {
			jSplitPane = new JSplitPane();
			jSplitPane.setOneTouchExpandable(true);
			jSplitPane.setDividerLocation(150);
			jSplitPane.setRightComponent(getJSplitPane1());
			jSplitPane.setLeftComponent(getJTree());
		}
		return jSplitPane;
	}

	/**
	 * This method initializes jTree	
	 * 	
	 * @return javax.swing.JTree	
	 */
	private JTree getJTree() {
		if (jTree == null) {
			DefaultMutableTreeNode root = new DefaultMutableTreeNode("Configuration");
			DefaultMutableTreeNode modelschild = new DefaultMutableTreeNode("Models");
			 HashMap mhm=ModelTypes.getMap();
			Set ms=mhm.keySet();
			Iterator mit=ms.iterator();
			while(mit.hasNext())
			{
				String key= (String) mit.next();
				String value=(String) mhm.get(key);
				modelschild.add( new DefaultMutableTreeNode(key));
				
			}
			root.add(modelschild);
			DefaultMutableTreeNode datasourceschild = new DefaultMutableTreeNode("DataSources");
			 HashMap dhm=DataSourceTypes.getMap();
			
			Set ds=dhm.keySet();
			Iterator dit=ds.iterator();
			
			int i=0;
//			DefaultMutableTreeNode child[] = null;
			
			while(dit.hasNext())
			{
				DefaultMutableTreeNode mapping=new DefaultMutableTreeNode("mapping");
				DefaultMutableTreeNode properties=new DefaultMutableTreeNode("properties");
				
				String key= (String) dit.next();
				String value=(String) mhm.get(key);
				
				HashMap mappinghm=MappingXMLFiles.getMap(key);
				Iterator mappingit=mappinghm.keySet().iterator();
				while(mappingit.hasNext())
				{
					String mkey=(String)mappingit.next();
					DefaultMutableTreeNode tempnode=new DefaultMutableTreeNode(mkey);
					mapping.add(tempnode);
					
				}
				DefaultMutableTreeNode child= new DefaultMutableTreeNode(key);
				child.add(mapping);
				child.add(properties);
				datasourceschild.add(child);
				i++;
			}
			
			root.add(datasourceschild);
			

			jTree = new JTree(root);
			jTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
				public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
					String name=null;
					if(jTree.getLastSelectedPathComponent()!=null)
						name=jTree.getLastSelectedPathComponent().toString();
					System.out.println("name="+name);
					jTable.setVisible(false);
					jEditorPane.setText("");
					HashMap mhm=ModelTypes.getMap();
					if(mhm.containsKey(name))
					{
						//meaning one model is selected
						HashMap mxmlhm=ModelXMLFiles.getMap();
						String dir=ModelXMLFiles.getDir();
						if(!mxmlhm.get(name).equals(""))
						{
							String filepath=dir+mxmlhm.get(name);
							
							XMLOperator xmlo=new XMLOperator();
							HashMap modelattrhm=xmlo.getModelAttrsFromXML(filepath);
							
							Object columnNames[] = { "Order","Name", "Type ID", "Type Name","Nominal Values","Date Format","Description"};
							Set modelas=modelattrhm.keySet();
					
							
							
							Object rowData[][]=new Object[modelas.size()][7];
							Iterator mait=modelas.iterator();
							
							List modelal=new ArrayList();
							while(mait.hasNext())
							{
								modelal.add((String)mait.next());
							}
							
							//sorting
							Collections.sort(modelal);
							Iterator malit=modelal.iterator();
							int j=0;
							while(malit.hasNext())
							{
								String attname=(String) malit.next();
								ModelAttribute ma=(ModelAttribute) modelattrhm.get(attname);
								rowData[j][0]=j+1;
								rowData[j][1]=ma.getAttributeName();
								rowData[j][2]=ma.getAttributeTypeId();
								rowData[j][3]=ma.getAttributeTypeName();
								rowData[j][4]=ma.getNomialValues();
								rowData[j][5]=ma.getDateFormat();
								rowData[j][6]=ma.getDescription();
								j++;
							}
							TableModel tablemodel = new DefaultTableModel(rowData, columnNames);
	
							jTable.setModel(tablemodel);
							
							TableRowSorter sorter = new TableRowSorter(tablemodel);
	
							jTable.setRowSorter(sorter);
							jTable.setVisible(true);
							
							
							FileInputStream fis;
							try {
								fis = new FileInputStream(filepath);
								doc=kit.createDefaultDocument();
								doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);   
								kit.read(fis, doc, 0);
								
								
								jEditorPane.setText(doc.getText(0,doc.getLength()));
								jEditorFilePath=filepath;
							} catch (FileNotFoundException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							} catch (IOException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							} catch (BadLocationException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							}
						}
						else
						{
							//no xml file
							String filen=System.getProperties().getProperty("user.dir")+System.getProperties().getProperty("file.separator")+"models"+System.getProperties().getProperty("file.separator");
							 JFileChooser chooser = new JFileChooser();
							    FileNameExtensionFilter filter = new FileNameExtensionFilter(
							        "XML Files", "xml");
							    chooser.setFileFilter(filter);
							    File file=new File(filen);
							    chooser.setSelectedFile(file);
							    int returnVal = chooser.showOpenDialog(fcd);
							    if(returnVal == JFileChooser.APPROVE_OPTION) {
							       System.out.println("You chose to open this file: " +
							            chooser.getSelectedFile().getAbsolutePath());
							    }
							    if(chooser.getSelectedFile()!=null)
							    {
							    	String value=chooser.getSelectedFile().getName();
							    	System.out.println(value);
							    	ModelXMLFiles.newOne(name, value);
							    }
						}
							
						
					}
					HashMap dhm=DataSourceTypes.getMap();
					if(dhm.containsKey(name))
					{
						//meaning one datasource is selected
						
						
						System.out.println("one datasource is selected");
					}
					HashMap totalXMLhm=MappingXMLFiles.getMap();
					
					if(totalXMLhm.containsKey(name))
					{
		
						System.out.println(name+" mapping is selected");
						//meaning one model is selected
						HashMap mxmlhm=MappingXMLFiles.getMap(name);
						String dir=MappingXMLFiles.getDir();
						System.out.println(name.toUpperCase());
						if(!mxmlhm.get(name.toUpperCase()).equals(""))
						{
							String filepath=dir+mxmlhm.get(name.toUpperCase());
							
							XMLOperator xmlo=new XMLOperator();
							HashMap modelattrhm=xmlo.getMappingAttrsFromXML(filepath);
							
							Object columnNames[] = { "Order","Name", "Model attribute name","Type ID", "Type Name","Nominal Values","Date Format","Description"};
							Set modelas=modelattrhm.keySet();
					
							
							
							Object rowData[][]=new Object[modelas.size()][8];
							Iterator mait=modelas.iterator();
							
							List modelal=new ArrayList();
							while(mait.hasNext())
							{
								modelal.add((String)mait.next());
							}
							
							//sorting
							Collections.sort(modelal);
							Iterator malit=modelal.iterator();
							int j=0;
							while(malit.hasNext())
							{
								String attname=(String) malit.next();
								MappingAttribute ma=(MappingAttribute) modelattrhm.get(attname);
								rowData[j][0]=j+1;
								rowData[j][1]=ma.getAttributeName();
								rowData[j][2]=ma.getModelAttributeName();
								rowData[j][3]=ma.getAttributeTypeId();
								rowData[j][4]=ma.getAttributeTypeName();
								rowData[j][5]=ma.getNomialValues();
								rowData[j][6]=ma.getDateFormat();
								rowData[j][7]=ma.getDescription();
								j++;
							}
							TableModel tablemodel = new DefaultTableModel(rowData, columnNames);
	
							jTable.setModel(tablemodel);
							
							TableRowSorter sorter = new TableRowSorter(tablemodel);
	
							jTable.setRowSorter(sorter);
							jTable.setVisible(true);
							
							
							FileInputStream fis;
							try {
								fis = new FileInputStream(filepath);
								doc=kit.createDefaultDocument();
								doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);   
								kit.read(fis, doc, 0);
								
								
								jEditorPane.setText(doc.getText(0,doc.getLength()));
								jEditorFilePath=filepath;
							} catch (FileNotFoundException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							} catch (IOException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							} catch (BadLocationException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							}
						}
						else
						{
							String filen=System.getProperties().getProperty("user.dir")+System.getProperties().getProperty("file.separator")+"mappings"+System.getProperties().getProperty("file.separator");
							 JFileChooser chooser = new JFileChooser();
							    FileNameExtensionFilter filter = new FileNameExtensionFilter(
							        "XML Files", "xml");
							    chooser.setFileFilter(filter);
							    File file=new File(filen);
							    chooser.setSelectedFile(file);
							    int returnVal = chooser.showOpenDialog(fcd);
							    if(returnVal == JFileChooser.APPROVE_OPTION) {
							       System.out.println("You chose to open this file: " +
							            chooser.getSelectedFile().getAbsolutePath());
							    }
							    if(chooser.getSelectedFile()!=null)
							    {
							    	String value=chooser.getSelectedFile().getName();
							    	MappingXMLFiles.newOne(name.toUpperCase(), value);
							    }
						}
									
								
					}
							
					if(name==null)
					{
						
					}
					else
					if(name.equalsIgnoreCase("properties"))
					{
						TreePath tp=jTree.getSelectionPath();
						
						String parentname=tp.getParentPath().getLastPathComponent().toString();
						
						//dir name
						String dir=System.getProperties().getProperty("user.dir")+System.getProperties().getProperty("file.separator")+"properties"+System.getProperties().getProperty("file.separator");
						
						//datasource name ,properties name;
						String propertiesname=parentname.toLowerCase()+".properties";
						
						propertiesfilepath=dir+propertiesname;
						File file=new File(propertiesfilepath);
						if(!file.exists())
						{
							try {
								file.createNewFile();
								PropertiesFileOperator pfo=new PropertiesFileOperator(dir+propertiesname);
								pfo.load();
								HashMap phm=pfo.getPropertyMap();
								pfo.addProperty("key", "value");
								pfo.dispose();
							} catch (IOException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							}
						}
						System.out.println("filepath:"+propertiesfilepath);
						PropertiesFileOperator pfo=new PropertiesFileOperator(dir+propertiesname);
						pfo.load();
						HashMap phm=pfo.getPropertyMap();
						pfo.dispose();
						JDialog propertiesDialog = getJPropertiesDialog();
						propertiesDialog .pack();
						Point loc = getJFrame().getLocation();
						loc.translate(20, 20);
						propertiesDialog .setLocation(loc);
						propertiesDialog .setVisible(true);
						
						
						Object columnNames[] = { "Key","Value" };
						Set modelas=phm.keySet();
				
						
						
						Object rowData[][]=new Object[modelas.size()][3];
						Iterator mait=modelas.iterator();
						
						List modelal=new ArrayList();
						while(mait.hasNext())
						{
							modelal.add((String)mait.next());
						}
						
						//sorting
						Collections.sort(modelal);
						Iterator malit=modelal.iterator();
						int j=0;
						while(malit.hasNext())
						{
							String attname=(String) malit.next();
							String ma= (String) phm.get(attname);
//							rowData[j][0]=j+1;
							rowData[j][0]=attname;
							rowData[j][1]=ma;
						
							j++;
						}
						TableModel tablemodel = new DefaultTableModel(rowData, columnNames);

						jTable11.setModel(tablemodel);
						
						TableRowSorter sorter = new TableRowSorter(tablemodel);

						jTable11.setRowSorter(sorter);
						jTable11.setVisible(true);
						
						
						
					}
					System.out.println("valueChanged()"); // TODO Auto-generated Event stub valueChanged()
				}
			});
			
			jTree.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseReleased(java.awt.event.MouseEvent e) {
					
				    if(e.isPopupTrigger()){
				     final JTree tree = (JTree)e.getComponent();
				     TreePath path = tree.getPathForLocation(e.getX(),e.getY());

				    
				     
				     if(path==null){
					      JMenuItem del=new JMenuItem("refresh");
					     
					
					      JPopupMenu popupMenu1;
					      popupMenu1=new JPopupMenu();
					   
					 
					      popupMenu1.add(del);
					    
					      del.addActionListener(new ActionListener(){
					       //action
					       public void actionPerformed(ActionEvent e){
					        //file.delete();
					    	
					    	 jSplitPane.remove(jTree);
					    	 System.out.println("jtree false");
					    	  jTree=null;
					    	  jSplitPane.setLeftComponent(getJTree());
					    	  System.out.println("jtree repaint");
					    	  jTree.setVisible(true);
//					    	  getJTree();
					    	
//					    	   refresh();
					       } 
					      });
					      
					      
					      
					      //popup menu
					      popupMenu1.show(tree,e.getX(),e.getY());
					     }
				     else
				     {
				    	 tree.setSelectionPath(path);
					    //node 
				    	 
				    	 
				    	 
				    	 
					     if(path.getLastPathComponent().toString().equalsIgnoreCase("models")){
					      JMenuItem del=new JMenuItem("delete");
					     
					      JMenuItem newFile=new JMenuItem("new");
					
					      JPopupMenu popupMenu1;
					      popupMenu1=new JPopupMenu();
					      popupMenu1.add(newFile);
					 
					      popupMenu1.add(del);
					     
					      del.addActionListener(new ActionListener(){
					       //action
					       public void actionPerformed(ActionEvent e){
					        //file.delete();
					    	   HashMap modelTypeshm=ModelTypes.getMap();
					    	   HashMap modelhm=ModelXMLFiles.getMap();
					    	   
					    	   Object[] possibleValues = modelTypeshm.keySet().toArray();
					    	   Object selectedValue = JOptionPane.showInputDialog(null, 
					    	   "Choose one model", "Delete", JOptionPane.INFORMATION_MESSAGE, null,
					    	   possibleValues, possibleValues[0]);
  	  
					    	   String key=((String) selectedValue).toUpperCase();
					    	   if(modelTypeshm.containsKey(key))
					    	   {
					    		   ModelTypes.delete(key);
					    		   ModelXMLFiles.delete(key);
					    	   }
					    	   jTree.updateUI();
					       } 
					      });
					      
					      newFile.addActionListener(new ActionListener(){
						       //action
						       public void actionPerformed(ActionEvent e){
						        //file.delete();
						    	   
						    	   String inputValue = JOptionPane.showInputDialog("Please input the name of new model:"); 
						    	   HashMap modelTypeshm=ModelTypes.getMap();
						    	   HashMap modelhm=ModelXMLFiles.getMap();
						    	   String key=inputValue.toUpperCase();
						    	   if(modelTypeshm.containsKey(key))
						    	   {
						    		   JOptionPane.showMessageDialog(null, "Alert", "This model already exists", JOptionPane.ERROR_MESSAGE); 
						    	   }
						    	   else
						    	   {
						    		   String value="0";
						    		   for(int i=0;i<modellimit;i++)
						    		   {
						    			   value=String.valueOf(i);
//						    			
						    			if(!modelTypeshm.containsValue(value))  
						    			{
						    				break;
						    			}
						    		   }
						    		  ModelTypes.newOne(key, value);
						    		  ModelXMLFiles.newOne(key, "");
						    	   }
						    	   jTree.updateUI();
						    	 } 
						      });
						      
					      
					      
					      //popup menu
					      popupMenu1.show(tree,e.getX(),e.getY());
					     }
					     
					     
					     
					     //datasources
					     if(path.getLastPathComponent().toString().equalsIgnoreCase("Datasources")){
						      JMenuItem del=new JMenuItem("delete");
						     
						      JMenuItem newFile=new JMenuItem("new");
						
						      JPopupMenu popupMenu1;
						      popupMenu1=new JPopupMenu();
						      popupMenu1.add(newFile);
						 
						      popupMenu1.add(del);
						     
						      del.addActionListener(new ActionListener(){
						       //action
						       public void actionPerformed(ActionEvent e){
						        //file.delete();
						    	   HashMap datasourceTypeshm=DataSourceTypes.getMap();
						    	   
						    	   
						    	   Object[] possibleValues = datasourceTypeshm.keySet().toArray();
						    	   Object selectedValue = JOptionPane.showInputDialog(null, 
						    	   "Choose one DataSource", "Delete", JOptionPane.INFORMATION_MESSAGE, null,
						    	   possibleValues, possibleValues[0]);
	  	  
						    	   String key=((String) selectedValue).toUpperCase();
						    	   if(datasourceTypeshm.containsKey(key))
						    	   {
						    		   DataSourceTypes.delete(key);
						    		   HashMap Mappinghm=MappingXMLFiles.getMap(key);
						    		   Iterator it=Mappinghm.keySet().iterator();
						    		   while(it.hasNext())
						    		   {
						    			   String mappingkey=(String) it.next();
						    			   MappingXMLFiles.delete(mappingkey);
						    		   }
						    	   }
						    	   jTree.updateUI();
						       } 
						      });
						      
						      newFile.addActionListener(new ActionListener(){
							       //action
							       public void actionPerformed(ActionEvent e){
							        //file.delete();
							    	   
							    	   String inputValue = JOptionPane.showInputDialog("Please input the name of new data source:"); 
							    	   HashMap datasourceTypeshm=DataSourceTypes.getMap();
							    	   
							    	   String key=inputValue.toUpperCase();
							    	   if(datasourceTypeshm.containsKey(key))
							    	   {
							    		   JOptionPane.showMessageDialog(null, "Alert", "This data source already exists", JOptionPane.ERROR_MESSAGE); 
							    	   }
							    	   else
							    	   {
							    		   String value="0";
							    		   for(int i=0;i<datasourcelimit;i++)
							    		   {
							    			   value=String.valueOf(i);
//							    			
							    			if(!datasourceTypeshm.containsValue(value))  
							    			{
							    				break;
							    			}
							    		   }
							    		  DataSourceTypes.newOne(key, value);
							    		  
							    		  // create 
							    	   }
							    	   jTree.updateUI();
							    	 } 
							      });
							      
						      
						      
						      //popup menu
						      popupMenu1.show(tree,e.getX(),e.getY());
						     }
						     
					     
					     
					     
					     if(path.getLastPathComponent().toString().equalsIgnoreCase("mapping")){
						     final String parent=path.getParentPath().getLastPathComponent().toString(); 
					    	 JMenuItem del=new JMenuItem("delete");
			
						      JMenuItem newFile=new JMenuItem("new");
						
						      JPopupMenu popupMenu1;
						      popupMenu1=new JPopupMenu();
						      popupMenu1.add(newFile);
						 
						      popupMenu1.add(del);
						   
						      del.addActionListener(new ActionListener(){
						       //action
						       public void actionPerformed(ActionEvent e){
						        //file.delete();
						    	 
						    	   HashMap mappinghm=MappingXMLFiles.getMap(parent);
						    	   
						    	   Object[] possibleValues = mappinghm.keySet().toArray();
						    	   Object selectedValue = JOptionPane.showInputDialog(null, 
						    	   "Choose one mapping", "Delete", JOptionPane.INFORMATION_MESSAGE, null,
						    	   possibleValues, possibleValues[0]);
	  	  
						    	   String key=((String) selectedValue).toUpperCase();
						    	   if(mappinghm.containsKey(key))
						    	   {
						    		  
						    		   MappingXMLFiles.delete(key);
						    	   }
						    	   tree.updateUI();
						       } 
						      });
						      
						      newFile.addActionListener(new ActionListener(){
							       //action
							       public void actionPerformed(ActionEvent e){
							        //file.delete();
							    	   
							    	   String inputValue = JOptionPane.showInputDialog("Please input the name of new mapping(e.g. MYSPACE.PERSON):"); 
							    	  
							    	   HashMap mappinghm=MappingXMLFiles.getMap();
							    	   String key=inputValue.toUpperCase();
							    	   if(mappinghm.containsKey(key))
							    	   {
							    		   JOptionPane.showMessageDialog(null, "Alert", "This mapping already exists", JOptionPane.ERROR_MESSAGE); 
							    	   }
							    	   else
							    	   {
							    		  String value="";
							    		  MappingXMLFiles.newOne(key, value);
							    	   }
							    	   tree.updateUI();
							    	 } 
							      });
						      
						      //popup menu
						      popupMenu1.show(tree,e.getX(),e.getY());
						     }
				     }
				     
				    }
				    
				   
				    
					System.out.println("mouseReleased()"); // TODO Auto-generated Event stub mouseReleased()
				}
			});
		
			
		}
		return jTree;
	}

	/**
	 * This method initializes jSplitPane1	
	 * 	
	 * @return javax.swing.JSplitPane	
	 */
	private JSplitPane getJSplitPane1() {
		if (jSplitPane1 == null) {
			jSplitPane1 = new JSplitPane();
			jSplitPane1.setOrientation(JSplitPane.VERTICAL_SPLIT);
			jSplitPane1.setDividerLocation(150);
			jSplitPane1.setTopComponent(getJScrollPane());
			jSplitPane1.setBottomComponent(getJScrollPane1());
			jSplitPane1.setOneTouchExpandable(true);
		}
		return jSplitPane1;
	}

	/**
	 * This method initializes jScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setViewportView(getJTable());
		}
		return jScrollPane;
	}

	/**
	 * This method initializes jTable	
	 * 	
	 * @return javax.swing.JTable	
	 */
	private JTable getJTable() {
		if (jTable == null) {
			jTable = new JTable();
		}
		return jTable;
	}

	/**
	 * This method initializes jEditorPane	
	 * 	
	 * @return javax.swing.JEditorPane	
	 */
	private JEditorPane getJEditorPane() {
		if (jEditorPane == null) {
			jEditorPane = new JEditorPane();
			// Instantiate a XMLEditorKit with wrapping enabled.
			kit = new XMLEditorKit(); 
			
			 // Set the wrapping style.
//			 ((Object) kit).setWrapStyleWord(true);
			 kit.setAutoIndentation(true);
			 kit.setTagCompletion(true);
			 
			 jEditorPane.setEditorKit( kit); 
			 
			 // Set the font style.
			 jEditorPane.setFont( new Font( "Courier", Font.PLAIN, 12)); 
			 jEditorPane.addMouseListener(new java.awt.event.MouseAdapter() {
			 	public void mouseReleased(java.awt.event.MouseEvent e) {
				    if(e.isPopupTrigger()){
					     final JEditorPane tree = (JEditorPane) e.getComponent();
					     
					     
					    //node 
					   
					      JMenuItem save=new JMenuItem("save");
					      JMenuItem saveas=new JMenuItem("save as ...");
					    
					
					      JPopupMenu popupMenu1;
					      popupMenu1=new JPopupMenu();
					      popupMenu1.add(save);
					      popupMenu1.add(saveas);
					    
					      
					      
					      save.addActionListener(new ActionListener(){
					       //action
					       public void actionPerformed(ActionEvent e){
					        //file.delete();
					    	  
					    	  File file=new File(jEditorFilePath);
					    	  if(file.exists())
					    	  {
					    		  file.delete();
					    		  try {
									file.createNewFile();
								} catch (IOException e1) {
									// TODO Auto-generated catch block
									e1.printStackTrace();
								}
					    	  }
					    	  try {
					    		  FileWriter fos=new FileWriter(file);
					    		  Document doc = jEditorPane.getDocument();

					    		  
								kit.write(fos, doc, 0, doc.getLength());
							} catch (FileNotFoundException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							} catch (IOException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							} catch (BadLocationException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							}
					    	  
					       } 
					      });
					      
					      
					      
					      saveas.addActionListener(new ActionListener(){
						       //action
						       public void actionPerformed(ActionEvent e){
						        //file.delete();
						    	  
						    		String filen=System.getProperties().getProperty("user.dir")+System.getProperties().getProperty("file.separator")+"instances"+System.getProperties().getProperty("file.separator");
									 JFileChooser chooser = new JFileChooser();
									    FileNameExtensionFilter filter = new FileNameExtensionFilter(
									        "XML Files", "xml");
									    chooser.setFileFilter(filter);
									    File file1=new File(filen);
									    chooser.setSelectedFile(file1);
									    int returnVal = chooser.showSaveDialog(fcd);
									    if(returnVal == JFileChooser.APPROVE_OPTION) {
									       System.out.println("save file: " +
									            chooser.getSelectedFile().getAbsolutePath());
									    }

									String filename=chooser.getSelectedFile().getAbsolutePath();
						    	   
						    	  File file=new File(filename);
						    	  if(file.exists())
						    	  {
						    		  file.delete();
						    		  try {
										file.createNewFile();
									} catch (IOException e1) {
										// TODO Auto-generated catch block
										e1.printStackTrace();
									}
						    	  }
						    	  try {
									FileWriter fos=new FileWriter(file);
									Document doc = jEditorPane.getDocument();
									kit.write(fos, doc, 0, doc.getLength());
								} catch (FileNotFoundException e1) {
									// TODO Auto-generated catch block
									e1.printStackTrace();
								} catch (IOException e1) {
									// TODO Auto-generated catch block
									e1.printStackTrace();
								} catch (BadLocationException e1) {
									// TODO Auto-generated catch block
									e1.printStackTrace();
								}
						    	  
						       } 
						      });
					      
					      
					      //popup menu
					      popupMenu1.show(tree,e.getX(),e.getY());
					    
					     }
			 		System.out.println("mouseReleased()"); // TODO Auto-generated Event stub mouseReleased()
			 	}
			 });
			 
			 // Set the tab size
			 jEditorPane.getDocument().putProperty( PlainDocument.tabSizeAttribute, new Integer(4));
			 
			 // Set a style
			 kit.setStyle( XMLStyleConstants.ATTRIBUTE_NAME, new Color( 255, 0, 0), Font.BOLD);
			 
			 // Put the editor in a panel that will force it to resize, when a different view is choosen.
			 

		}
		return jEditorPane;
	}

	/**
	 * This method initializes jMenu	
	 * 	
	 * @return javax.swing.JMenu	
	 */
	private JMenu getJMenu() {
		if (jMenu == null) {
			jMenu = new JMenu();
			jMenu.setName("Evaluation");
			jMenu.setText("Evaluation");
			jMenu.add(getJMenuItem());
			jMenu.add(getJMenuItem1());
			jMenu.add(getJMenuItem2());
			jMenu.addMenuKeyListener(new javax.swing.event.MenuKeyListener() {
				public void menuKeyPressed(javax.swing.event.MenuKeyEvent e) {
//					weka.gui.GUIChooser.main(null);
					System.out.println("menuKeyPressed()"); // TODO Auto-generated Event stub menuKeyPressed()
				}
				public void menuKeyTyped(javax.swing.event.MenuKeyEvent e) {
					System.out.println("1");
				}
				public void menuKeyReleased(javax.swing.event.MenuKeyEvent e) {
					System.out.println("2");
				}
			});
			jMenu.addMenuListener(new javax.swing.event.MenuListener() {
				public void menuSelected(javax.swing.event.MenuEvent e) {
//					weka.gui.GUIChooser.main(null);
					System.out.println("menuSelected()"); // TODO Auto-generated Event stub menuSelected()
				}
				public void menuDeselected(javax.swing.event.MenuEvent e) {
				}
				public void menuCanceled(javax.swing.event.MenuEvent e) {
				}
			});
		}
		return jMenu;
	}

	/**
	 * This method initializes jMenuItem	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJMenuItem() {
		if (jMenuItem == null) {
			jMenuItem = new JMenuItem();
			jMenuItem.setText("Naive Bayes ROC");
			jMenuItem.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					String filen=System.getProperties().getProperty("user.dir")+System.getProperties().getProperty("file.separator")+"instances"+System.getProperties().getProperty("file.separator");
					 JFileChooser chooser = new JFileChooser();
					    FileNameExtensionFilter filter = new FileNameExtensionFilter(
					        "Arff Files", "arff");
					    chooser.setFileFilter(filter);
					    File file=new File(filen);
					    chooser.setSelectedFile(file);
					    int returnVal = chooser.showOpenDialog(fcd);
					    if(returnVal == JFileChooser.APPROVE_OPTION) {
					       System.out.println("You chose to open this file: " +
					            chooser.getSelectedFile().getAbsolutePath());
					    }
					if(chooser.getSelectedFile()!=null)
					{
						String filename=chooser.getSelectedFile().getAbsolutePath();
						
						String[] args={filename,"1"};
						try {
							GenerateROC.main(args);
						} catch (Exception e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
					}
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
				}
			});
		}
		return jMenuItem;
	}

	/**
	 * This method initializes jScrollPane1	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane1() {
		if (jScrollPane1 == null) {
			jScrollPane1 = new JScrollPane();
			jScrollPane1.setViewportView(getJEditorPane());
		}
		return jScrollPane1;
	}

	/**
	 * This method initializes jMenuItem1	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJMenuItem1() {
		if (jMenuItem1 == null) {
			jMenuItem1 = new JMenuItem();
			jMenuItem1.setText("Decision Trees ROC");
			jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					String filen=System.getProperties().getProperty("user.dir")+System.getProperties().getProperty("file.separator")+"instances"+System.getProperties().getProperty("file.separator");
					 JFileChooser chooser = new JFileChooser();
					    FileNameExtensionFilter filter = new FileNameExtensionFilter(
					        "Arff Files", "arff");
					    chooser.setFileFilter(filter);
					    File file=new File(filen);
					    chooser.setSelectedFile(file);
					    int returnVal = chooser.showOpenDialog(fcd);
					    if(returnVal == JFileChooser.APPROVE_OPTION) {
					       System.out.println("You chose to open this file: " +
					            chooser.getSelectedFile().getAbsolutePath());
					    }
				    if(chooser.getSelectedFile()!=null)
					{
						String filename=chooser.getSelectedFile().getAbsolutePath();
						String[] args={filename,"2"};
						try {
							GenerateROC.main(args);
						} catch (Exception e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
					}
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
				}
			});
		}
		return jMenuItem1;
	}

	/**
	 * This method initializes jMenuItem2	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJMenuItem2() {
		if (jMenuItem2 == null) {
			jMenuItem2 = new JMenuItem();
			jMenuItem2.setText("Support Vector Machines ROC");
			jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					String filen=System.getProperties().getProperty("user.dir")+System.getProperties().getProperty("file.separator")+"instances"+System.getProperties().getProperty("file.separator");
					 JFileChooser chooser = new JFileChooser();
					    FileNameExtensionFilter filter = new FileNameExtensionFilter(
					        "Arff Files", "arff");
					    chooser.setFileFilter(filter);
					    File file=new File(filen);
					    chooser.setSelectedFile(file);
					    int returnVal = chooser.showOpenDialog(fcd);
					    if(returnVal == JFileChooser.APPROVE_OPTION) {
					       System.out.println("You chose to open this file: " +
					            chooser.getSelectedFile().getAbsolutePath());
					    }
				    if(chooser.getSelectedFile()!=null)
					{
						String filename=chooser.getSelectedFile().getAbsolutePath();
						String[] args={filename,"3"};
						try {
							GenerateROC.main(args);
						} catch (Exception e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
					}
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
				}
			});
		}
		return jMenuItem2;
	}



	/**
	 * This method initializes jPropertiesDialog	
	 * 	
	 * @return javax.swing.JDialog	
	 */
	private JDialog getJPropertiesDialog() {
		if (jPropertiesDialog == null) {
			jPropertiesDialog = new JDialog(getJFrame());
			jPropertiesDialog.setSize(new Dimension(305, 201));
			jPropertiesDialog.setContentPane(getJPropertiesContentPane());
			jPropertiesDialog.setTitle("Properties");
		}
		return jPropertiesDialog;
	}

	/**
	 * This method initializes jPropertiesContentPane	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPropertiesContentPane() {
		if (jPropertiesContentPane == null) {
			jPropertiesContentPane = new JPanel();
			jPropertiesContentPane.setLayout(new BorderLayout());
			jPropertiesContentPane.add(getJScrollPane2(), BorderLayout.CENTER);
		}
		return jPropertiesContentPane;
	}

	/**
	 * This method initializes jScrollPane2	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane2() {
		if (jScrollPane2 == null) {
			jScrollPane2 = new JScrollPane();
			jScrollPane2.setViewportView(getJTable11());
		}
		return jScrollPane2;
	}

	/**
	 * This method initializes jTable11	
	 * 	
	 * @return javax.swing.JTable	
	 */
	private JTable getJTable11() {
		if (jTable11 == null) {
			jTable11 = new JTable();
			jTable11.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseReleased(java.awt.event.MouseEvent e) {
					
					if(e.isPopupTrigger()){
					     final JTable tree = (JTable) e.getComponent();
					     
					     
					    //node 
					   
					      JMenuItem save=new JMenuItem("save");
					      JMenuItem saveas=new JMenuItem("save as ...");
					      JMenuItem add=new JMenuItem("add");
					      JMenuItem del=new JMenuItem("delete");
					
					      JPopupMenu popupMenu1;
					      popupMenu1=new JPopupMenu();
					      popupMenu1.add(save);
					      popupMenu1.add(saveas);
					      popupMenu1.add(add);
					      popupMenu1.add(del);
					    
					      final TableModel tm=tree.getModel();
				    	  final HashMap temphm=new HashMap();
				    	  for(int i=0;i<tm.getRowCount();i++)
				    	  {
				    		  String key=(String) tm.getValueAt(i, 0);
				    		  String value=(String) tm.getValueAt(i, 1);
				    		  temphm.put(key, value);
				    	  }
					      
					      save.addActionListener(new ActionListener(){
					       //action
					       public void actionPerformed(ActionEvent e){
					        //file.delete();
					    	  
					    	  File file=new File(propertiesfilepath);
					    	  if(file.exists())
					    	  {
					    		  file.delete();
					    		  try {
									file.createNewFile();
								} catch (IOException e1) {
									// TODO Auto-generated catch block
									e1.printStackTrace();
								}
					    	  }
					    	  
					    	  PropertiesFileOperator pfo=new PropertiesFileOperator(propertiesfilepath);
					    	  pfo.load();
					    	  pfo.setPropertyMap(temphm);
					    	  pfo.save();
					    	  pfo.dispose();
					       } 
					      });
					      
					      
					      
					      saveas.addActionListener(new ActionListener(){
						       //action
						       public void actionPerformed(ActionEvent e){
						        //file.delete();
						    	  
						    		String filen=System.getProperties().getProperty("user.dir")+System.getProperties().getProperty("file.separator")+"properties"+System.getProperties().getProperty("file.separator");
									 JFileChooser chooser = new JFileChooser();
									    FileNameExtensionFilter filter = new FileNameExtensionFilter(
									        "Properties Files", "properties");
									    chooser.setFileFilter(filter);
									    File file1=new File(filen);
									    chooser.setSelectedFile(file1);
									    int returnVal = chooser.showSaveDialog(fcd);
									    if(returnVal == JFileChooser.APPROVE_OPTION) {
									       System.out.println("save file: " +
									            chooser.getSelectedFile().getAbsolutePath());
									    }

									String filename=chooser.getSelectedFile().getAbsolutePath();
						    	   
						    	  File file=new File(filename);
						    	  if(file.exists())
						    	  {
						    		  file.delete();
						    		  try {
										file.createNewFile();
									} catch (IOException e1) {
										// TODO Auto-generated catch block
										e1.printStackTrace();
									}
						    	  }
						    	  PropertiesFileOperator pfo=new PropertiesFileOperator(propertiesfilepath);
						    	  pfo.load();
						    	  pfo.setPropertyMap(temphm);
						    	  pfo.saveAs(filename);
						    	  pfo.dispose();
						    	  
						       } 
						      });
					      
					      add.addActionListener(new ActionListener(){
						       //action
						       public void actionPerformed(ActionEvent e){
						        //file.delete();
						    	  
						    	   JDialog jAddDialog = getJAddDialog();
						    	   jAddDialog.pack();
									Point loc = getJFrame().getLocation();
									loc.translate(20, 20);
									jAddDialog.setLocation(loc);
									jAddDialog.setVisible(true);
									
									
						    	  
						       } 
						      });
					      
					      del.addActionListener(new ActionListener(){
						       //action
						       public void actionPerformed(ActionEvent e){
						        //file.delete();
						    	  
						    	   int selectionrow=tree.getSelectedRow();
						    	   String key=(String) tm.getValueAt(selectionrow, 0);
						    	   String value=(String) tm.getValueAt(selectionrow, 1);
						    	   int result=JOptionPane.showConfirmDialog(null, "Are you sure to delete this property? key:"+key+" value:"+value, "Warning", JOptionPane.OK_CANCEL_OPTION);
						    	   System.out.println("result:"+result);
						    	   if(result==0)
						    	   {
						    		   PropertiesFileOperator pfo=new PropertiesFileOperator(propertiesfilepath);
								    	  pfo.load();
								    	  
								    	  pfo.deleteProperty(key);
								    	  pfo.save();
								    	  pfo.dispose();
						    	   }
						    	   else
						    	   {
						    		   
						    	   }
						    			        
						    	  
						       } 
						      });
					      //popup menu
					      popupMenu1.show(tree,e.getX(),e.getY());
					    
					     }
					
					System.out.println("mouseReleased()"); // TODO Auto-generated Event stub mouseReleased()
				}
			});
		}
		return jTable11;
	}

	/**
	 * This method initializes jAlterDialog	
	 * 	
	 * @return javax.swing.JDialog	
	 */
	private JDialog getJAlterDialog() {
		if (jAlterDialog == null) {
			jAlterDialog = new JDialog(getJFrame());
			jAlterDialog.setSize(new Dimension(222, 111));
			jAlterDialog.setTitle("Alter");
			jAlterDialog.setContentPane(getJAlterContentPane());
		}
		return jAlterDialog;
	}

	/**
	 * This method initializes jAlterContentPane	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJAlterContentPane() {
		if (jAlterContentPane == null) {
			jAlterLabel = new JLabel();
			jAlterLabel.setText("JLabel");
			jAlterContentPane = new JPanel();
			jAlterContentPane.setLayout(new BorderLayout());
			jAlterContentPane.add(jAlterLabel, BorderLayout.CENTER);
		}
		return jAlterContentPane;
	}

	/**
	 * This method initializes jAddDialog	
	 * 	
	 * @return javax.swing.JDialog	
	 */
	private JDialog getJAddDialog() {
		if (jAddDialog == null) {
			jAddDialog = new JDialog(getJFrame());
			jAddDialog.setTitle("Add");
			jAddDialog.setSize(new Dimension(319, 106));
			jAddDialog.setContentPane(getJAddContentPane());
		}
		return jAddDialog;
	}

	/**
	 * This method initializes jAddContentPane	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJAddContentPane() {
		if (jAddContentPane == null) {
			jAddValueLabel = new JLabel();
			jAddValueLabel.setText("Value:");
			jAddKeyLabel = new JLabel();
			jAddKeyLabel.setText("Key:");
			jAddContentPane = new JPanel();
			jAddContentPane.setLayout(new FlowLayout());
			jAddContentPane.add(jAddKeyLabel, null);
			jAddContentPane.add(getJAddKeyTextField(), null);
			jAddContentPane.add(jAddValueLabel, null);
			jAddContentPane.add(getJAddValueTextField(), null);
			jAddContentPane.add(getJAddConfirmButton(), null);
			jAddContentPane.add(getJAddResetButton(), null);
		}
		return jAddContentPane;
	}

	/**
	 * This method initializes jAddKeyTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJAddKeyTextField() {
		if (jAddKeyTextField == null) {
			jAddKeyTextField = new JTextField();
			jAddKeyTextField.setColumns(8);
			jAddKeyTextField.setPreferredSize(new Dimension(92, 25));
		}
		return jAddKeyTextField;
	}

	/**
	 * This method initializes jAddValueTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJAddValueTextField() {
		if (jAddValueTextField == null) {
			jAddValueTextField = new JTextField();
			jAddValueTextField.setColumns(8);
			jAddValueTextField.setPreferredSize(new Dimension(92, 25));
		}
		return jAddValueTextField;
	}

	/**
	 * This method initializes jAddConfirmButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJAddConfirmButton() {
		if (jAddConfirmButton == null) {
			jAddConfirmButton = new JButton();
			jAddConfirmButton.setText("Confirm");
			jAddConfirmButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					String key=jAddKeyTextField.getText().trim().toUpperCase();
					String value=jAddValueTextField.getText().trim();
					if(key.equalsIgnoreCase("")||value.equalsIgnoreCase(""))
					{
						JOptionPane.showMessageDialog(null, "key or value cannot be empty string!", "Warning", 1);
					}
					else
					{
						PropertiesFileOperator pfo=new PropertiesFileOperator(propertiesfilepath);
						pfo.load();
						pfo.addProperty(key, value);
						pfo.save();
						pfo.dispose();
						
						
						jAddDialog.setVisible(false);
						jAddKeyTextField.setText("");
						jAddValueTextField.setText("");
						jTable11.updateUI();
					}
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
				}
			});
		}
		return jAddConfirmButton;
	}

	/**
	 * This method initializes jAddResetButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJAddResetButton() {
		if (jAddResetButton == null) {
			jAddResetButton = new JButton();
			jAddResetButton.setText("Reset");
			jAddResetButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					jAddKeyTextField.setText("");
					jAddValueTextField.setText("");
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
				}
			});
		}
		return jAddResetButton;
	}

	
	public void refresh()
	{
		this.getJFrame().setVisible(false);
		this.getJFrame().repaint();
		this.getJTree().updateUI();
		this.getJFrame().setVisible(true);
	}
	/**
	 * This method initializes jExMenuItem3	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJExMenuItem3() {
		if (jExMenuItem3 == null) {
			jExMenuItem3 = new JMenuItem();
			jExMenuItem3.setText("Run GUI");
			jExMenuItem3.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					Experimenter ex=new Experimenter(true);
					
//				    	GUI ex=new GUI();
//				    	TaskLauncher tl=new TaskLauncher();
				        	
//				    	tl.show();
//				    	tl.setVisible(true);
//				    	ex.add(tl);
//					TaskManagerPanel ex=new TaskManagerPanel();
//				   Runtime run=Runtime.getRuntime();
//				   String command="java -cp .:moa.jar:weka.jar -javaagent:sizeofag.jar moa.gui.TaskLauncher";
//				   try {
//					run.exec(command);
//				} catch (IOException e1) {
//					// TODO Auto-generated catch block
//					e1.printStackTrace();
//				}
					
					final javax.swing.JFrame jf = 
					      new javax.swing.JFrame("Weka Experimenter Visualize");
					    jf.setSize(600,500);
					    jf.getContentPane().setLayout(new BorderLayout());
					    jf.getContentPane().add(ex, BorderLayout.CENTER);
					    jf.addWindowListener(new java.awt.event.WindowAdapter() {
					      public void windowClosing(java.awt.event.WindowEvent e) {
					      jf.dispose();
					      }
					    });
					    jf.setVisible(true);
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
				}
			});
		}
		return jExMenuItem3;
	}

	/**
	 * Launches this application
	 */
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				
				SpamDetectionFramework application = new SpamDetectionFramework();
				WindowUtilities.setNativeLookAndFeel();

				application.getJFrame().setVisible(true);
			}
		});
	}

}
